package com.todod.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.todod.entity.ResultData;
import com.todod.service.FileinfoService;

/**
 * 附件操作
 * 
 * @ClassName: FileinfoController
 * @Description:
 * @author gsh
 * @date 2019年8月12日
 *
 */
@RestController
@RequestMapping("/fileinfo")
public class FileinfoController extends BaseManageController {
	@Autowired
	private FileinfoService fileinfoService;

	@Value("${file.visit}")
	private String visi;

	/**
	 * 
	 * @Title: upload
	 * @Description: 上传图片和pdf
	 * @author：gsh
	 * @date: 2019年5月6日
	 * @param request
	 * @param response
	 * @return
	 * @return ModelAndView
	 */
	@PostMapping("/upload")
	public ResultData upload(@RequestAttribute Long _userId, HttpServletRequest request, HttpServletResponse response) {

		try {
			request.setCharacterEncoding("utf-8");

			String path = fileinfoService.saveUploadFile(_userId, request);

			return ResultData.success("ok", visi + path);
		} catch (Exception e) {
			e.printStackTrace();

			return ResultData.error("error");
		}
	}

}
